package com.ymatou.iapi.liveseller.testcase;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.ymatou.iapi.liveseller.parameter.GetLiveCategoryListBean;
import com.ymatou.iapi.liveseller.service.GetLiveActivityProductsCall;
import com.ymatou.iapi.liveseller.service.GetLiveCategoryListCall;
import com.ymatou.iapi.prodstock.parameter.GetCurrentTimeBean;
import com.ymatou.iapi.prodstock.service.GetCurrentTimeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.LiveRoomWapper;

public class Ts_GetLiveCategoryList {

	private static GetLiveCategoryListBean getLiveCategoryListBean;
	private static GetLiveCategoryListCall getLiveCategoryListCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取分类列表");
	}

	@Before
	public void caseUp() {
		getLiveCategoryListBean=new GetLiveCategoryListBean();
		getLiveCategoryListCall=new GetLiveCategoryListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getLiveCategoryListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetLiveCategoryList_001() {
		Logger.start(true,"获取分类列表");
		try {
			getLiveCategoryListBean.setAppid("autotest");
			getLiveCategoryListCall.setData(getLiveCategoryListBean);
			getLiveCategoryListCall.callService();
			String Code = getLiveCategoryListCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			//固定 livecategory
			//TODO 这个数据为固定数据
			List<Map> list = new LiveRoomWapper().selectLivecategory();
			Logger.verifyEquals(list.size(), getLiveCategoryListCall.getJsonObject().get("Data").getAsJsonObject().get("LiveCategoryList").getAsJsonArray().size(), "品类条数验证");
			JsonArray jo = getLiveCategoryListCall.getJsonObject().get("Data").getAsJsonObject().get("LiveCategoryList").getAsJsonArray();
			int i=0;
			for (Map map : list) {
				Logger.verifyEquals(map.get("LiveCategoryId").toString(), jo.get(i).getAsJsonObject().get("LiveCategoryId").getAsString(), "排序");
				i++;
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
